#ifndef _KC_SSLRECEIVER_H__KC_
#define _KC_SSLRECEIVER_H__KC_

#include "Receiver.h"
#include "../../comm/ssl/SSLServerSession.h"
#include "../../logs/Logger.h"

namespace kc_sf
{
	/** Receiver, który rozmawia z klientem na zabezpieczonym kanale SSL */
	class SSLReceiver : public Receiver
	{
		public:

			SSLReceiver() {}
			explicit SSLReceiver( const Connection &connection );
			SSLReceiver( CommCommon *comm, const Connection &connection );
			~SSLReceiver();

			CommRequestHandler *getInstance( const Connection &connection ) const;
			void operator ()();

			CommResult processEhlo( const Command &cmd );
			CommResult processAuthPlain();
			CommResult processAuthLogin();
			CommResult processStartTLS();
			CommResult processMailFrom(const Command & cmd );
			CommResult processRcpt( const Command & cmd);
			CommResult processData();
			CommResult processBdat( const Command & cmd );

		private:

			SSLServerSession *r_safe_session;
			Logger r_ssl_logger;

			bool isEndOfMsg(const std::string & text) const;
			bool stripSourceRoute(const std::string &route_mailbox, Address &mailbox) const;

			bool checkAuthentication( const std::string &login, const std::string &passwd );

			CommResult recvAndDecodeCredentials( std::string &decoded );
	};
}

#endif // _KC_SSLRECEIVER_H__KC_
